<?php echo $this->render('layouts/__header.phtml'); ?>
<?php echo $this->render('layouts/__nav.phtml'); ?>

<link rel="stylesheet" type="text/css" href="/css/task.css" />
<script type="text/javascript" src="/js/calendar/calendar.js"></script>
<script type="text/javascript" src="/js/calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="/js/calendar/calendar-setup.js"></script>
<style type="text/css">@import url(/js/calendar/calendar.css); </style>
<script type="text/javascript" src="/js/rpt/swfobject.js"></script>
<script type="text/javascript" src="/js/base.js"></script>
<script type="text/javascript">
window.addEvent('domready', function(){

	Calendar.setup({inputField:"date_start",ifFormat:"%Y-%m-%d",button:"calendarBeginButton",singleClick:true,step:1});
	Calendar.setup({inputField:"date_start",ifFormat:"%Y-%m-%d",button:"vBeginDate",singleClick:true,step:1});
	
	Calendar.setup({inputField:"date_end",ifFormat:"%Y-%m-%d",button:"calendarEndButton",singleClick:true,step:1});
	Calendar.setup({inputField:"date_end",ifFormat:"%Y-%m-%d",button:"vEndDate",singleClick:true,step:1});
	
	Calendar.setup({inputField:"actual_date_start",ifFormat:"%Y-%m-%d",button:"calendarActualBeginButton",singleClick:true,step:1});
	Calendar.setup({inputField:"actual_date_start",ifFormat:"%Y-%m-%d",button:"vActualBeginDate",singleClick:true,step:1});
	
	Calendar.setup({inputField:"actual_date_end",ifFormat:"%Y-%m-%d",button:"calendarActualEndButton",singleClick:true,step:1});
	Calendar.setup({inputField:"actual_date_end",ifFormat:"%Y-%m-%d",button:"vActualEndDate",singleClick:true,step:1});

	<?php if (sizeof($this->children) > 0) : ?>
	var so = new SWFObject("/js/rpt/ampie.swf", "ampie", "500", "240", "4", "#FFFFFF");
	so.addVariable("path", "/js/rpt/");
	so.addVariable("settings_file", escape("/task/piesetting"));
	so.addVariable("data_file", escape("/task/piedata"));
	so.addVariable("preloader_color", "#999999");
	so.addParam("wmode", "transparent");
	so.write("flashcontent");
	// For Task Assign
	var form_name = 'task_new_form';
	$(form_name).getElements('input[name^=weight]').each(function(item, index){
		item.addEvent('change', function(e){
			if (countWeight(form_name)) {
				var request_uri = '<?php echo $this->pie_url;?>?ajax=1&t='+(new Date()).getTime();
				new Ajax(request_uri, {
					method: 'get',
					data: Object.toQueryString({
						data: getWeight(form_name)
					}),
					onComplete: function(){
						if ('success' == this.response.text) {
							so.write("flashcontent");
						}
					}
				}).request();
			}
		});
	});
	<?php endif; ?>

	$('savebtn').addEvent('click', function(e){	
		e = new Event(e);
		validate('task_new_form');
		e.stop();
	});

	$('cancelbtn').addEvent('click', function(e){	
		e = new Event(e);
		loadopen('<?php echo $this->cancel_url;?>');
		e.stop();
	});
});
</script>

		<form id="task_new_form" action="<?php echo $this->this_url; ?>" method="post">
		<input type="hidden" id="sup_task_id" name="sup_task_id" value="<?php echo $this->sup_id; ?>" />
		<input type="hidden" id="progress" name="progress" />
		<input type="hidden" id="save" name="save" />
		
			<h2><?php if ($this->sup_task) echo "Add New Sub Task for '{$this->sup_task['title']}'"; else echo "Add New Root Task"; ?></h2>
			
			<?php if ($this->errors) : ?>
			<div class="errormsgbox">
			<?php foreach ($this->errors as $error_msg) echo '<p>'.$error_msg.'</p>'; ?>
			</div>
			<?php endif; ?>
			
			<table class="table550">
				<tr><td>&nbsp;</td></tr>
				
			<!-- Task Common Column Start -->
				
				<tr>
					<td colspan="2">
						<span class="left">Title</span>
						<input name="title" type="text" class="title" />
					</td>
				    <td>
				    	<span class="left">Property</span>
					    <?php 
					    $property_id = ($this->sup_task) ? $this->sup_task['property_id'] : 0;
					    echo $this->formSelect('property_id', $property_id, null, $this->entites['property']);
					    ?>
					</td>
				</tr>
				
				<tr>
					<td>
						<span class="left">Requester</span>
						<?php 
						$request_id = ($this->sup_task) ? $this->sup_task['request_id'] : 0;
						echo $this->formSelect('request_id', $request_id, null, $this->entites['requester']);
						?>
					</td>
				    <td>
						<span class="left">PM</span>
						<?php 
						$manager_id = ($this->sup_task) ? $this->sup_task['manager_id'] : 0;
						echo $this->formSelect('manager_id', $manager_id, null, $this->entites['manager']);
						?>
					</td>
				    <td>
						<span class="left">Assign To</span>
						<?php echo $this->formSelect('developer_id', 0, null, $this->entites['engineer']) ?>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<span class="left">Task Type</span>
						<?php 
						$task_type = ($this->sup_task) ? $this->sup_task['task_type'] : 0;
						echo $this->formSelect('task_type', $task_type, array('style' => 'width:288px'), $this->entites['type']);
						?>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<span class="left">Prior Refer</span>
						<?php 
						$task_prior = ($this->sup_task) ? $this->sup_task['prior_reference'] : 0;
						echo $this->formSelect('prior_reference', $task_prior, array('style' => 'width:288px'), $this->entites['prior_reference']);
						?>
					</td>
				</tr>
				<tr>
					<td colspan="3"><span class="left">Man Hours</span>
					<input name="man_hour" type="text" class="man_hour" />&nbsp;man×hour</td>
				</tr>
				<tr>
					<td colspan="3">
						<span class="left">Roadmap</span>
						<input name="roadmap_id" type="text" maxlength="7" class="man_hour" value="" />&nbsp;7(chars)
					</td>
				</tr>
				<tr>
					<td colspan="3">
						<span class="left">CVS Tag</span>
						<input name="cvs_tag" type="text" maxlength="50" class="man_hour" value="" />
					</td>
				</tr>
				<tr>
					<td colspan="3">
						<span class="left">Start Date</span>
						<input id="date_start" name="date_start" value="<?php echo "0000-00-00"; ?>" style="width: 80px;" type="text" readonly />
						<input type="button" id="calendarBeginButton" class="cal" style="width:20px" />
					</td>
			    </tr>
				<tr>
					<td colspan="3">
						<span class="left">Due Date</span>
						<input id="date_end" name="date_end" value="<?php echo "0000-00-00"; ?>" style="width: 80px;" type="text" readonly />
						<input type="button" id="calendarEndButton" class="cal" style="width:20px" />
					</td>
				</tr>
				<tr>
					<td colspan="3">
						<span class="left">ActualStart</span>
						<input id="actual_date_start" name="actual_date_start" value="<?php echo "0000-00-00"; ?>" style="width: 80px;" type="text" readonly />
						<input type="button" id="calendarActualBeginButton" class="cal" style="width:20px" />
					</td>
			    </tr>
				<tr>
					<td colspan="3">
						<span class="left">Actual End</span>
						<input id="actual_date_end" name="actual_date_end" value="<?php echo "0000-00-00"; ?>" style="width: 80px;" type="text" readonly />
						<input type="button" id="calendarActualEndButton" class="cal" style="width:20px" />
					</td>
				</tr>
			<!-- Task Common Column End -->
				
			<!-- Task Assign Weight Start -->
				<?php if (sizeof($this->children) > 0) : ?>
				<tr>
					<td colspan="3"><span class="left_long">Sub Tasks Weight</span></td>
				</tr>
				<tr>
					<td colspan="3">
						<div id="flashcontent" style="height:200px;">
							<strong>You need to upgrade your Flash Player</strong>
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="3">
					<?php foreach ($this->children as $child) : ?>
					<div class="childtask"><?php echo $child['title']?>&nbsp;:&nbsp;<input type="text" name="weight_subtask_<?php echo $child['id']?>" class="taskweight" maxlength="3" value="<?php echo $child['weight']?>" />&nbsp;%</div>
					<?php endforeach;?>
					<div class="childtask"><font style="color:red">Current Task</font>&nbsp;:&nbsp;<input type="text" name="weight" class="taskweight" maxlength="2" value="0" />&nbsp;%</div>
					</td>
				</tr>
				<tr>
					<td colspan="3">
						<div id="weight_notice">
							<font style="color:black;font-weight:bold">* You can change the weight of the subtasks above !</font>
						</div>
					</td>
				</tr>
				<?php endif; ?>
			<!-- Task Assign Weight End -->
				<tr>
					<td colspan="3">
					<div style="font-weight:bold;padding:5px 0;">Description</div>
					<textarea name="description"></textarea>
					</td>
			    </tr>
			    
			    <tr><td colspan="3" class="spacing"></td></tr>
				<tr>
					<td colspan="3"><input type="button" id="savebtn" value="Save" class="but" /><input id="cancelbtn" type="button" value="Cancel" class="but" /></td>
				</tr>
			</table>

		</form>

		<div id="savingbox" style="display:none;padding:2px 0px 0px 8px;width:125px;height:20px;text-align:center;position:absolute;top:0px;right:0px;background:#CC0000;color:#fff;z-index:10000;"><b>Saving ...</b></div>
		<div id="loadingbox" style="display:none;padding:2px 0px 0px 8px;width:125px;height:20px;text-align:center;position:absolute;top:0px;right:0px;background:#CC0000;color:#fff;z-index:10000;"><b>Loading ...</b></div>

<?php echo $this->render('layouts/__footer.phtml'); ?>